package com.bluefish.bltuan.module.mail;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;

import com.bluefish.bltuan.module.Category;

@Entity
public class Subscriber implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 580163233673757464L;
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Integer id;
	
	private String email;
	
	private boolean sended;
	
	@OneToOne(fetch = FetchType.LAZY)
	private Category city;
	
	public Subscriber(){
		
	}
	
	public Subscriber(String email, Category city){
		this.email = email;
		this.city = city;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public boolean isSended() {
		return sended;
	}

	public void setSended(boolean sended) {
		this.sended = sended;
	}
	
	public Category getCity() {
		return city;
	}
	
	public void setCity(Category city) {
		this.city = city;
	}
	
	@Override
	public boolean equals(Object obj) {
		if(obj != null && obj instanceof Subscriber){
			Subscriber temp = (Subscriber)obj;
			return this.email.equals(this.email) && this.city.equals(temp.getCity());
		}
		return false;
	}
	
	@Override
	public int hashCode() {
		return this.email.hashCode() * 24 + this.city.getId();
	}

}
